package com.anran.verificationcode.controller;

import com.anran.common.constant.ApplicationNameConstants;
import com.anran.common.module.dto.NumberCodeDTO;
import com.anran.common.response.ResponseResult;
import com.anran.verificationcode.service.NumberCodeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping(ApplicationNameConstants.ONLINE_SERVICE_VERIFICATION_CODE)
public class NumberCodeController {

    @Resource
    private NumberCodeService numberCodeService;

    final static Logger logger = LoggerFactory.getLogger(NumberCodeController.class);

    /**
     * 根据长度获取验证码
     */
    @GetMapping("/numberCode/{size}")
    public ResponseResult<NumberCodeDTO> numberCode(@PathVariable("size") int size){
        try {
            ResponseResult<NumberCodeDTO> result = numberCodeService.getNumberCode(size);
            return result;
        } catch (Exception e) {
            logger.error("获取验证码错误：{}", e);
            return ResponseResult.fail("获取验证码错误");
        }
    }






}
